#pragma once

#include "Task.h"

class GameSession : public Task
{
public:
							GameSession(void);
	virtual					~GameSession(void);

public:
	static GameSession*		CreateByName(const char* name, const char* arg);

protected:
	virtual void			OnEvent(Event* evt);

public:
	const char*				GetName()							{ return m_Name.c_str(); }
	const char*				GetArgument()						{ return m_Argument.c_str(); }

	Camera*					GetCamera()							{ return m_Camera; }
	const Vector3&			GetLookAtPos()						{ return m_LookAtPos; }

	void					SetCamera(Camera* camera);
	void					SetLookAtPos(const Vector3& lookAt)	{ m_LookAtPos = lookAt; }
	
	float					GetSessionTime()					{ return m_sessionTime; }

protected:
	friend class			GameApp;
	void					StartSession();
	void					StopSession();

protected:
	std::string				m_Name;
	std::string				m_Argument;

protected:
	SceneManager*			m_SceneManager;
	Camera*					m_Camera;
	Vector3					m_LookAtPos;

protected:
	float					m_sessionTime;
	float					m_startTime;

protected:
	EventChannel*			m_MainChannel;
	EventChannel*			m_TaskChannel;

public:
	class Registry;
};

///////////////////////////////////////////////////////////////////

class SessionStopEvent : public Event
{
	DECLARE_EVENT(0);

	SessionStopEvent() { }
};

//////////////////////////////////////////////////////////////////////////

class GameSession::Registry
{
	typedef GameSession* (*ConstructorFn) (const char* arg);

public:
	Registry(ConstructorFn constructor, const char* name);

public:
	static std::string GetSessionList();

private:
	friend class		GameSession;
	ConstructorFn		Constructor;
	const char*			Name;
	Registry*			Next;

	static Registry*&	GetHead();
	static Registry*	Add(Registry* r);
};

#define REGISTER_GAMESESSION(NAME, CLASS) \
	static GameSession* _CreateSession_##CLASS(const char* args) {return new CLASS(); } \
	static GameSession::Registry _reg##CLASS(_CreateSession_##CLASS, NAME);				